package com.as.client.charts;


import com.gwtext.client.data.ArrayReader;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.FloatFieldDef;
import com.gwtext.client.data.MemoryProxy;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.chart.yui.LineChart;
import com.gwtext.client.widgets.chart.yui.NumericAxis;
import com.gwtext.client.widgets.chart.yui.SeriesDefY;
import com.gwtext.client.widgets.layout.VerticalLayout;



public class ChartPanel extends Panel{
	
	public ChartPanel(String title, String x, String y1, String y2) {

			
		this.setPaddings(15);
		this.setLayout(new VerticalLayout(15));
		
		MemoryProxy proxy = new MemoryProxy(getData()); 
		
		RecordDef recordDef = new RecordDef(  
				                new FieldDef[]{  
				                          new StringFieldDef(x),  
				                         new FloatFieldDef(y1),  
				                         new FloatFieldDef(y2)  
				                   }  
				         );  
		
		 ArrayReader reader = new ArrayReader(recordDef);
		 final Store store = new Store(proxy, reader);
		 store.load(); 
		 
		 SeriesDefY[] seriesDef = new SeriesDefY[]{ 
				 new SeriesDefY(y1, y1),  
                 new SeriesDefY(y2, y2)  
		 };
		 
		 NumericAxis currencyAxis = new NumericAxis();  
		 currencyAxis.setMinimum(800);  
//		 currencyAxis.setLabelFunction("formatCurrencyAxisLabel");  
		 final LineChart chart = new LineChart();  
		 chart.setTitle(title);  
		 chart.setWMode("transparent"); 
		 chart.setStore(store); 
		 chart.setSeries(seriesDef); 
		 chart.setXField(x);  
		 chart.setYAxis(currencyAxis);
//		 chart.setDataTipFunction("getDataTipText");
		 chart.setExpressInstall("js/yui/assets/expressinstall.swf"); 
		 chart.setWidth(350);
		 chart.setHeight(250);
		 chart.setAutoScroll(true);
		 chart.setVisible(true);
		 
		 this.add(chart);
		
		
		this.setAutoHeight(true);
		this.setAutoWidth(true);
		this.setAutoScroll(true);
		this.setVisible(true);
	}
	
	
	private static Object[][] getData() {  
		         return new Object[][]{  
		                 new Object[]{"January", new Double(880.00), new Double(894.68)},  
		                 new Object[]{"February", new Double(880.00), new Double(901.35)},  
		                 new Object[]{"March", new Double(880.00), new Double(889.32)},  
		                 new Object[]{"April", new Double(880.00), new Double(884.71)},  
		                 new Object[]{"May", new Double(910.00), new Double(879.811)},  
		                new Object[]{"June", new Double(910.00), new Double(897.95)}
		               //  new Object[]{"July", null, null, new Double(877.95)}
		          };  
		      } 
	
//	 private Object[][] createObject(Hashtable ht){
//		 Enumeration<String> en = ht.keys();
//		 Object[][] o= new Object [ht.size()][2];
//		 int j =0;
//		 while (en.hasMoreElements()){
//			 String mac = en.nextElement(); 
//			// String alias = Users.USERS.get(mac).getAlias();
//			 o[j][0]=mac;
//			// o[j][1]=alias;
//			 j++;
//		 }
//		 return o; 
//	 }

}